/**
 * 0063
 *  
 * @Author : roryrywang
 * @DateTime : 2024/8/16 0:36
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int uniquePathsWithObstacles(vector<vector<int>> &obstacleGrid) {
        if (obstacleGrid[0][0] == 1 || obstacleGrid[obstacleGrid.size() - 1][obstacleGrid[0].size() - 1] == 1) {
            return 0;
        }
        int f[obstacleGrid.size()][obstacleGrid[0].size()];
        f[0][0] = 1;
        for (int i = 0; i < obstacleGrid.size(); ++i) {
            for (int j = 0; j < obstacleGrid[0].size(); ++j) {
                if (obstacleGrid[i][j] == 1) {
                    f[i][j] = 0;
                    continue;
                }
                if (i == 0 && j == 0)continue;
                f[i][j] = 0;
                if (i > 0)f[i][j] += f[i - 1][j];
                if (j > 0)f[i][j] += f[i][j - 1];
            }
        }
        return f[obstacleGrid.size() - 1][obstacleGrid[0].size() - 1];
    }
};

int main() {

    return 0;
}